import { GET_NEWS } from '../actionType'

// 仓库数据
export interface IState {
  news: Array<any>
}
interface IAction {
  type: symbol
  news?: Array<any>
}

const defaultState: IState = {
  news: [{ name: '官官', id: 'guanguan' }],
}

const reducer = (state: IState = defaultState, action: IAction) => {
  // reducer 不允许直接修改 state的数据
  const newState = { ...state }
  const { news = [] } = action
  switch (action.type) {
    case GET_NEWS:
      newState.news = news
      break
    default:
      console.log('news没有发现type', action.type)
      return state
  }
  return newState
}

export default reducer
